//
//  CheckLabel.m
//  NekaPrice
//
//  Created by yu on 2018/6/13.
//  Copyright © 2018年 ma c. All rights reserved.
//

#import "CheckLabel.h"

@implementation CheckLabel



- (instancetype)initWithFrame:(CGRect)frame andDefaultText:(NSString *)defaultText key:(NSString *)key {
    if (self = [super initWithFrame:frame]) {
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 3;
        self.layer.borderWidth = 1;
        self.layer.borderColor = [UIColor lightGrayColor].CGColor;
        self.textColor = [UIColor whiteColor];
        self.font = [UIFont systemFontOfSize:12];
        
        self.defaultText = defaultText;
        self.isDefault = YES;
        _key = key;
        self.backgroundColor = [UIColor whiteColor];
        self.edgeInsets = UIEdgeInsetsZero;
        self.userInteractionEnabled = NO;
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        self.edgeInsets = UIEdgeInsetsMake(0, 20, 0, 20);
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 4;
        self.layer.borderWidth = 0.5;
        self.layer.borderColor = [UIColor lightGrayColor].CGColor;
        self.textColor = [UIColor whiteColor];
        self.font = [UIFont systemFontOfSize:14];
        self.textAlignment = NSTextAlignmentCenter;
        self.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.2];
        
    }
    return self;
}

- (void)setIsDefault:(BOOL)isDefault {
    _isDefault = isDefault;
    if (_isDefault) {
        self.text = self.defaultText;
    }
}

- (NSString *)value {
    if (_isDefault) {
        return @"";
    }else {
        return self.text;
    }
}

- (void)setText:(NSString *)text {
    [super setText:text];
    CGFloat width = [text widthWithFixedHeight:30 andEdgeInsets:self.edgeInsets attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]}];
    CGRect rect = self.frame;
    rect.size.width = width;
    self.frame = rect;
}









@end
